package galaxy.drawer.drawable;

import particles.Particle;
import particles.ParticleSystem;
import processing.core.PGraphics;
import processing.core.PVector;

public class Explosion implements Drawable {
	private ParticleSystem system;
	private int lifetime;
	private int color;
	
	public Explosion(PVector position, int particles, int lifetime,
			float rotation, float speed, float dispersion, int color,
			float angle, double width, double height)
	{
		system = new ParticleSystem(particles, position, lifetime, rotation);
		system.explode(speed, dispersion, angle, width, height); //angle represents absolute angle for the explosion's direction
		this.lifetime = lifetime;
		this.color = color;
	}
	
	public void draw(PGraphics g)
	{
		for (int i = 0; i < lifetime; i++) {
			system.update();
		}
		
		g.stroke(color >> 16 & 255, color >> 8 & 255, color & 255);
		
		for (Particle p : system.getParticles()) {
			// g.color(p.getLifetime());
			g.point(p.getLocation().x, p.getLocation().y);
		}
	}
}
